<template>
  <div class="text-over-tooltip-components">
    <el-tooltip :effect="effect"
                :disabled="isDisabledTooltip"
                :content="content"
                :placement="placement">
      <div class="ellipsis"
           :class="className"
           @mouseover="onMouseOver(refName)">
        <span :ref="refName">{{content}}</span>
      </div>
    </el-tooltip>
  </div>
</template>

<script>
export default {
  name: 'TextOverTooltip',
  props: {
    content: String,
    className: String,
    refName: String,
    effect: {
      type: String,
      default: () => {
        return 'dark';
      }
    },
    placement: {
      type: String,
      default: () => {
        return 'bottom';
      }
    },
  },
  data () {
    return {
      isDisabledTooltip: true
    };
  },
  methods: {
    onMouseOver (str) {
      let parentWidth = this.$refs[str].parentNode.offsetWidth;
      let contentWidth = this.$refs[str].offsetWidth;
      this.isDisabledTooltip = contentWidth <= parentWidth;
    }
  }
};
</script>

<style lang="scss" scoped>
.text-over-tooltip-components {
  .ellipsis {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .fs20 {
    font-size: 20px;
    font-weight: 600;
    color: green;
    line-height: 22px;
  }
  .fs12 {
    font-size: 12px;
    font-weight: 400;
    color: orange;
    line-height: 14px;
  }
}
</style>
